function showCheck(a){
	var c = document.getElementById("myCanvas");
  var ctx = c.getContext("2d");
	ctx.clearRect(0,0,1000,1000);
	ctx.font = "80px 'Microsoft Yahei'";
	ctx.fillText(a,0,100);
	ctx.fillStyle = "rgba(255,255,255,.9)";
}
var code ;    
function createCode(){       
    code = "";      
    var codeLength = 4;
    var selectChar = new Array(1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','j','k','l','m','n','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z');      
    for(var i=0;i<codeLength;i++) {
       var charIndex = Math.floor(Math.random()*60);
      code +=selectChar[charIndex];
    }      
    if(code.length != codeLength){
      createCode();      
    }
    showCheck(code);
}
  //验证验证码是否一致        
function validate () {
    var url="../UserController/findByUserAndName";
    var data={userName:$("#userName").val(),userPwd:$("#userPwd").val()};
    $.post(url,data,function(obj){
        if(obj.num==0){
            layer.msg(obj.msg, {
                icon: 2,
                time: 2000 //1秒关闭(如果不配置默认三秒)
            });
            return false;
        }else{
            layer.msg(obj.msg, {
                icon: 1,
                time: 2000 //1秒关闭(如果不配置默认三秒)
            },function(){
                var urlone="../UserController/findById";
                var dataone={userName:$("#userName").val()};
                $.post(urlone,dataone,function(objs){
                    if(objs.userPermissions==1){
                        window.location.href = "adminindex.html";
                    }else{
                        window.location.href = "userindex.html";
                    }
                },"json");

            });
        }
    },"json");
}